/**
 * 1
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-9-27 下午6:22
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }

    int max_val = -0x3f3f3f3f;
    int min_val = 0x3f3f3f3f;
    int max_idx = 0;
    int min_idx = 0;

    for (int i = 0; i < nums.size(); ++i) {
        if (nums[i] > max_val) {
            max_val = nums[i];
            max_idx = i;
        }
        if (nums[i] < min_val) {
            min_val = nums[i];
            min_idx = i;
        }
    }

    swap(nums[0], nums[max_idx]);
    swap(nums[nums.size() - 1], nums[min_idx]);

    for (int num: nums) {
        cout << num << " ";
    }
    cout << endl;

    return 0;
}